
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import promiseMiddleware from './promiseMiddleware';
import asyncActionCallbackMiddleware from './asyncActionCallbackMiddleware';
import minPendingTimeMiddleware from './minPendingTime';
import reducers from '../reducers';

const nextRootReducer = require('../reducers/index').default;

const logger = createLogger();

const middlewares = [
  thunkMiddleware,
  promiseMiddleware,
  asyncActionCallbackMiddleware,
  minPendingTimeMiddleware,
  logger,
];

export default function configureStore(initialState) {
  const store = applyMiddleware(
    ...middlewares,
  )(createStore)(reducers, initialState);

  if (module.hot) {
    module.hot.accept(() => {
      store.replaceReducer(nextRootReducer);
    });
  }

  return store;
}

